package com.gitee.ywj1352.client;

import com.gitee.ywj1352.client.handler.RpcDecoder;
import com.gitee.ywj1352.client.handler.RpcEncoder;
import com.gitee.ywj1352.common.Protocol.RpcRequest;
import com.gitee.ywj1352.common.Protocol.RpcResponse;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;


/**
 * Created by luxiaoxun on 2016-03-16.
 */
public class RpcClientInitializer extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        ChannelPipeline cp = socketChannel.pipeline();
        cp.addLast(new RpcEncoder<RpcRequest>());
        cp.addLast(new LengthFieldBasedFrameDecoder(65536, 0, 4, 0, 0));
        cp.addLast(new RpcDecoder<RpcResponse>());
        cp.addLast(new RpcClientHandler());
    }
}
